/**
 * @Author: Nick Zhang <thesadboy@vip.qq.com>
 * @Description: 生成随机的趣味注释
 * @Date: 2024-06-19 20:53:33
 * @LastEditors: Nick Zhang <thesadboy@vip.qq.com>
 * @LastEditTime: 2024-06-20 09:49:28
 */
package com.nickzhang.jetbrains.file_description_plugin.actions

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.nickzhang.jetbrains.file_description_plugin.utils.CommentUtil
import com.nickzhang.jetbrains.file_description_plugin.utils.FunComments

class RandomFunAction : AnAction() {
    override fun actionPerformed(e: AnActionEvent) {
        val editor: Editor = e.getData(CommonDataKeys.EDITOR) ?: return
        val document = editor.document
        val file = FileDocumentManager.getInstance().getFile(document) ?: return
        val comment = FunComments.getRandomFunComment()
        document.let { CommentUtil.insertFunComment(it, file, comment) }
    }
}
